import * as actionTypes from '../actionTypes';

export const addCouner = () => {
  return {
    type: actionTypes.INCREMENT
  }
}

export const addCounerAsync = () => {
  return async dispatch => {
    await mockDebounce();
    dispatch({
      type: actionTypes.INCREMENT_ASYNC
    })
  }
}

export const decrementCouner = () => {
  return {
    type: actionTypes.DECREMENT
  }
}
// 模拟请求，延迟1秒在派发
export const decrementCounerAsync = () => {
  return async dispatch => {
    await mockDebounce();
    dispatch({
      type: actionTypes.DECREMENT_ASYNC
    })
  }
}

const mockDebounce = () => {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve();
    }, 1000);
  })
}
